package com.market.member.factory;

import com.block.common.util.ApplicationContextUtil;
import com.market.member.enums.LoginTypeEnum;
import com.market.member.service.ILoginTypeService;
import com.market.member.service.login.*;

import java.util.HashMap;
import java.util.Map;

public class LoginTypeFactory {

    private static final Map<String, Class<? extends ILoginTypeService>> serviceMap = new HashMap<>();
    static {
        serviceMap.put(LoginTypeEnum.VERIFY.getValue(), CodeLoginServiceImpl.class);
        serviceMap.put(LoginTypeEnum.QUICK.getValue(), QuickLoginServiceImpl.class);

        serviceMap.put(LoginTypeEnum.MOBILE.getValue(), MobileLoginServiceImpl.class);
        serviceMap.put(LoginTypeEnum.RANDOM.getValue(), RandomLoginServiceImpl.class);
        serviceMap.put(LoginTypeEnum.UNIONLOGIN.getValue(), UnionLoginServiceImpl.class);
    }

    public static ILoginTypeService getService(String loginType){
        if (serviceMap.containsKey(loginType)){
            Class<? extends ILoginTypeService> aClass = serviceMap.get(loginType);
            return ApplicationContextUtil.getBean(aClass);
        }
        return null;
    }

}